<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<%--<script type="text/javascript" src="js/jquery2.js"></script>--%>
<%--<script type="text/javascript" src="js/jquery2.sorted.js"></script>--%>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/ckform.js"></script>
<script type="text/javascript" src="js/common.js"></script>
	<script src="js/jquery.min.js?v=2.1.4"></script>
<style type="text/css">
body {font-size: 20px;
	padding-bottom: 40px;
	background-color: #e9e7ef;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
	<%--提示消息插件--%>
    <script src="js/Dream-Msg/lib/dream-msg.min.js"></script>
	<script>
		$(function(){
			getBlogPage(1);
		})
		//删除博客
		function deleteInfo(bid,btitle,pageNo) {
			if(confirm("你确定要删除【"+btitle+"】吗?")){
				// alert(bid+'---'+btitle)
				$.post("blog/deleteBlogById",{"bid":bid,"btitle":btitle},function (result) {
					if(result.status==1){
						//删除成功
						Dreamer.success(result.message);
						getBlogPage(pageNo)
					}else{
						Dreamer.error(result.message);
					}
				})
			}

		}

		function getBlogPage(pageNo) {
			$.post("blog/getBlogPage","pageNo="+pageNo,function (result) {
				// alert(JSON.stringify(result))
				let bloglist='';
				result.list.forEach(function(blog){
					bloglist+= `
                        <tr align="center">
							  <td>\${blog.btitle}</td>
							  <td>\${blog.btype.typename}</td>
							  <td>\${blog.user.truename}</td>
							  <td>\${blog.date}</td>
							  <td>
							   <a href="javascript:deleteInfo(\${blog.bid},'\${blog.btitle}',\${result.pageNum})">删除 </a>
							   &nbsp;&nbsp;&nbsp;&nbsp;
							   <a href="blog_detail.jsp?bid=\${blog.bid}">博客详情</a>
							  </td>
						</tr>
                    `;
				});
				$("#tbody").html(bloglist);
				//处理分页
				let start='';
				if(result.pageNum<=1){
					start+=`<a href="javascript:void(0)"><span style="color: #3a3c3c">首页</span></a>&nbsp;
                                <a href="javascript:void(0)"><span style="color: #3a3c3c">上一页</span></a>`;
				}else{
					start+=`<a href="javascript:getBlogPage(1)">首页</a>&nbsp;
                                <a href="javascript:getBlogPage(\${result.pageNum-1})">上一页</a>`;
				}
				let end='';
				if(result.pageNum>=result.pages){
					end+=`<a href="javascript:void(0)"><span style="color: #3a3c3c">下一页</span></a>&nbsp;
                                <a href="javascript:void(0)"><span style="color: #3a3c3c">末页</span></a>`;
				}else{
					end+=`<a href="javascript:getBlogPage(\${result.pageNum+1})">下一页</a>&nbsp;
                                <a href="javascript:getBlogPage(\${result.pages})">末页</a>`;
				}

				let nums='';
				result.navigatepageNums.forEach(function (num) {
					if(num==result.pageNum){
						nums+=`<a href="javascript:void(0)" style="color: red">\${num}</a>&nbsp;&nbsp;&nbsp;`;
					}else{
						nums+=`<a href="javascript:getBlogPage(\${num})">\${num}</a>&nbsp;&nbsp;&nbsp;`;
					}
				})

				let foot=`\${start}  【&nbsp;&nbsp;\${nums}】  \${end}   |||   总数据量:\${result.total}`;
				$("#pagenationId").html(foot)
			})
		}
	</script>
</head>
<body>
	<form class="form-inline definewidth m20" action="#" method="get">
	<a href="documentAdd.jsp">发布博客</a>

	</form>
	<table class="table table-bordered table-hover definewidth m10">
		<thead>
			<tr align="center">
				<th>博客标题</th>
				<th>博客类别</th>
				<th>作者</th>
				<th>发布日期</th>
				<th>管理菜单</th>
			</tr>
		</thead>
		<tbody id="tbody">
		   <%--存放行数据--%>

		</tbody>
		<tfoot id="tfoot">
			<%--设置分页信息--%>
			<tr>
				<td colspan="5" id="pagenationId">

				</td>
			</tr>
		</tfoot>
	</table>

</body>
</html>
